from google.appengine.ext import db, webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class Greeting(db.Model):   #Object Definition
    content = db.StringProperty(multiline=True)
    
#Applicant Data Model Classes
class ApplicantStub(db.Model):
    password = db.TextProperty() #required=True)
    first_name = db.TextProperty() #required=True)
    middle_initial = db.TextProperty()
    last_name = db.TextProperty() #required=True)
    cell_phone_number = db.PhoneNumberProperty() #required=True)
    email_address = db.EmailProperty()
    security_question_answer = db.TextProperty()
    email_or_text = db.TextProperty() #required=True)
    comments = db.TextProperty(indexed=False)

#GetStarted1 page - First Page of Info Gathering
class GetStarted1(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="em">
<html>
	<head>		
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
		<title>ResEdge - Get Started Page 1</title>
		<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
	</head>
	<body id="tab2">
	<img src="/Images/RawHeader1100.gif" />
	<ul id="tabnav">
	<li class="tab1"><a href="/HomeWebPage">Home</a></li>
	<li class="tab2"><a href="/GetStarted1">Get Started</a></li>
	<li class="tab3"><a href="/admin/">Retrieve Results</a></li>
	<li class="tab4"><a href="/admin/">Employers Portal</a></li>
	<li class="tab5"><a href="/admin/">F.A.Q.</a></li>
	<li class="tab6"><a href="/admin/">About ResEdge</a></li>
	</ul>
<h2>Distinguish Yourself And Your Resume with a ResEdge Report!</h2>
OK, let's get a Name and Password for you<br>
<form id="frmFirstForm" action="/firstfrm" method="post" name="frmElecConsent">
First Name: <input type="text" name="txtFirstName" /> Middle Initial: <input type="text" name="txtMiddleInitial" /> Last Name: <input type="text" name="txtLastName" /><br>
What Password Would You Like To Use: <input type="password" name="txtPassword" /><br><br>
Alright, now a phone number and email address:<br>
Cell Phone #: <input type="tel" name="inPhoneNumber" /> Email Address: <input type="text" name="txtEmailAdd" /><br>
Would you rather have messages from us go to Email or Text Message to Cell Phone? <input type="radio" name="selMessage" value="Email" checked="selected" /> Email<input type="radio" name="selMessage" value="CellPhone" /> Cell Phone<br>
<hr>Please select a Security Question and provide an Answer:<br>
<select name="txtSecQuestion"><option value="1">Mothers' Maiden Name:</option><option value="2">Favorite Color:</option><option value="3">Favorite Season:</option><option value="4">Favorite Month:</option></select> Answer: <input type="text" name="txtSecQuestionAnswer" />
<input type="submit" name="btnSubmitFirstSheet" value="Next" />
</form>
<a href="/ShowEntities">Show Entities</a></p>
<a href="/admin/">Admin Page</a></p>
<hr>
<p>Click the <button type=button id="btnFinGetStarted" style="color:blue" onClick="location.href='/firstfrm'"/>Finished!</button> button to Submit Your ResEdge Information.</p>
<p>Copyright 2011 by ResEdge LLC, All rights Reserved.  ResEdge is trademarked by ResEdge LLC  Terms and Conditions  Privacy Policy</p> 
</body>
</html>
	''')
#End of GetStarted1

class MainHandler(webapp.RequestHandler):
    def get(self):
        self.response.out.write('Hello world!')
#        self.response.out.write('<h2>My GuestBook</h2><ol>')
#        #greetings = db.GqlQuery("SELECT * FROM Greeting")
#        greetings = Greeting.all()
#        for greeting in greetings:
#            self.response.out.write('<li> %s' % greeting.content)
#        self.response.out.write('''
#            </ol><hr>
#            <form action="/sign" method=post>
#            <textarea name=content rows=3 cols=60></textarea>
#            <br><input type=submit value="Sign Guestbook">
#            </form>
#        ''')
        self.response.out.write("""<hr><p><a href="/show">Show Entities Page</a></p></body></html>""")
        
#START: ShowEntitiesPage
class ShowEntities(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/html"
        self.response.out.write("""<html><head><title>ResEdge Show Entities Test Page</title></head>
           <body><p>This is the Show Entities Page!<p><hr><ol>""")
        # Output a list of ApplicantStub entities
        q = ApplicantStub.all()
        for applicants in q:
        	self.response.out.write("<p>Name: %s<br>Email Address: %s</p>" % (applicants.first_name, applicants.email_address))
#        q = db.GqlQuery('SELECT * From ApplicantStub')
        # Link back to GetStarted Page
        self.response.out.write("""</ol><hr><p><a href="/GetStarted1">GetStarted Page</a></p></body></html>""")
#END: ShowEntitiesPage 

class GuestBook(webapp.RequestHandler):
    def post(self):
        greeting = Greeting()
        greeting.content = self.request.get('content')
        greeting.put()
        self.redirect('/')
        
#Constructor & Posting Of Data
class PostApplicantStub(webapp.RequestHandler):
    def post(self):
    	applicant = ApplicantStub() #Constructor
        applicant.password = self.request.get("txtPassword"),
        applicant.first_name = self.request.get("txtFirstName"),
        applicant.middle_initial = self.request.get("txtMiddleInitial"),
        applicant.last_name = self.request.get("txtLastName"),
        applicant.cell_phone_number = self.request.get("inPhoneNumber"),
        applicant.email_address = self.request.get("txtEmailAdd"),
        applicant.security_question_answer = (self.request.get("txtSecQuestion")+self.request.get("txtSecQuestionAnswer")),
        applicant.email_or_text = self.request.get("selMessage"),
        applicant.comments = self.request.get("txtComments"),
        applicant.key_name = self.request.get("inPhoneNumber")
        applicant.put()
        self.redirect('/admin/')

application = webapp.WSGIApplication([
    ('/', MainHandler),
    ('/sign', GuestBook),
    ('/show', ShowEntities),
], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == '__main__':
    main()